<?php
//我的■
InitGP(array("action","type","bid","commit","sn","page"),"GP",1); //初始化變量全局返回
include(INC_PATH."/groupbond.class.php");
$gb=new GroupBondClass();

switch ($type){	
case "available":
	$wherestr[]="state in(1,0,3)";
	$wherec[]="state in(1,0,3)";
	break;
case "appointment":
	$state=3;
	$wherestr[]="state='{$state}'";
	$wherec[]="state='{$state}'";
	break;		
case "used":
	$state=2;
	$wherestr[]="state='{$state}'";
	$wherec[]="state='{$state}'";
	break;	
case "expired":
	$wherestr[]="endtime <>0 and endtime<'{$timestamp}'";
	$wherec[]="endtime <>0 and endtime<'{$timestamp}'";
	break;	
case "all":
	break;
default:
	$state=0;
}

if ($type=="usetime" && GetNum($bid)) {
	$sid=$_SUSERS['sid'];
	$wherestr="bid='{$bid}' and sid='{$sid}'";
	editstate("groupbond","state",$wherestr,2);
	editstate("groupbond","usetime",$wherestr,$timestamp);
	showmessage("設置成功！","s.php?action=bond",true);
}
if ($type=="usenow" && GetNum($bid)) {
	$sid=$_SUSERS['sid'];
	$wherestr="bid='{$bid}' and sid='{$sid}'";
	editstate("groupbond","state",$wherestr,3);
	editstate("groupbond","usetime",$wherestr,$timestamp);
	showmessage("設置成功！","s.php?action=bond",true);
}

if(!empty($_SUSERS['sid'])){
	$sid=$_SUSERS['sid'];
	$wherestr[]="B.sid='{$sid}'";
	//處理搜索sn
	if (!empty($sn)) {
		$wherestr[]="B.sn like '%{$sn}%'";
		$wherec[]="sn like '%{$sn}%'";
	}
	
	$wherestr[]="B.uid <>  0";
	$wherec[]="uid <> 0";
	
	if(!empty($wherestr)) $wheresql = implode(' AND ', $wherestr);	//條件匯總
	//獲取當前頁碼
	
	$wherec[]="sid='{$sid}'";
	if(!empty($wherec)) $wherecount = implode(' AND ',$wherec);	//條件匯總
	
	$total=$gb->getcount($wherecount); 							  //總信息數
	$pagesize=15;												  //一頁顯示信息數
	$page = isset($page) ? max(1, intval($page)) : 1;             //處理頁碼變量
	$offset=($page-1)*$pagesize;   								  //偏移量
	$value=$gb->getdata("$offset,$pagesize",$wheresql,"","ALL"); //獲取團購數據
}


include template('suppliers_bond');//包含輸出指定模板
?>